<?php
namespace Inbox\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
//use Users\Form\RegisterForm;
class CreateController extends AbstractActionController
{

	public function indexAction()
	{
		$form = new CreateForm();
		$viewModel  = new ViewModel(array('form' =>
				$form));
		return $viewModel;
	}
	public function confirmAction()
	{
		$viewModel  = new ViewModel();
		return $viewModel;
	}
	public function processAction()
	{
		if (!$this->request->isPost()) {
			return $this->redirect()->toRoute(NULL ,
					array( 'controller' => 'create',
							'action' =>  'index'
					));
		}
		$post = $this->request->getPost();
		$form = new CreateForm();
		$inputFilter = new CreateFilter();
		$form->setInputFilter($inputFilter);
		$form->setData($post);
		if (!$form->isValid()) {
			$model = new ViewModel(array(
					'error' => true,
					'form'  => $form,
			));
			$model->setTemplate('product/create/index');
			return $model;
		}
		return $this->redirect()->toRoute(NULL , array(
				'controller' => 'create',
				'action' =>  'confirm'
		));
	}
	protected function createUser(array $data)
	{
		$sm = $this->getServiceLocator();
		$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
		$resultSetPrototype = new \Zend\Db\ResultSet\ResultSet();
		$resultSetPrototype->setArrayObjectPrototype(new
		  \Inbox\Model\Inbox);
		$tableGateway = new \Zend\Db\TableGateway\TableGateway('inbox',
				$dbAdapter, null, $resultSetPrototype);

		$product = new Inbox();
		$product->exchangeArray($data);
		$productTable = new UserTable($tableGateway);
		$productTable->saveUser($inbox);
		return true;
	}
}
?>